package com.zhiyizhen.handheld.component.message.view;

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.zhiyizhen.handheld.R;

public class BadgeImageView extends RelativeLayout {

    private TextView badgeCountTv;

    public BadgeImageView(Context context) {
        super(context);
        init(context);
    }

    public BadgeImageView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public BadgeImageView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    private void init(Context context) {
        inflate(context, R.layout.view_badge_image, this);
        badgeCountTv = findViewById(R.id.badgeCountTv);
    }

    @SuppressLint("SetTextI18n")
    public void setBadgeCount(int count) {
        if (count == 0) {
            badgeCountTv.setVisibility(GONE);
            return;
        }
        if (count > 99) {
            badgeCountTv.setText("99+");
        } else {
            badgeCountTv.setText(String.valueOf(count));
        }
        badgeCountTv.setVisibility(VISIBLE);
    }

}